package la.bbs558.entity.enums;

import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: Shanks
 * @date: 2023/12/16 17:41
 * @desc:
 */
@Getter
public enum PostProperty {
    NORMAL(1, "普通"),
    HOT(2, "精华"),
    TOP(3, "置顶");
    private Integer code;

    private String desc;

    PostProperty(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static PostProperty getByCode(Integer code) {
        for (PostProperty value : PostProperty.values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }

    public static List<Map<String, Object>> getPropertyList() {
        List<Map<String, Object>> list = new ArrayList<>();
        for (PostProperty value : PostProperty.values()) {
            Map<String, Object> map = new HashMap<>(2);
            map.put("label", value.getDesc());
            map.put("value", value.getCode());
            list.add(map);
        }
        return list;
    }
}
